package com.xin.springcloudconsumer.handler;

import com.xin.springcloudconsumer.config.ProjectUrlConfig;
import com.xin.springcloudconsumer.exception.LoginAspectException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@ControllerAdvice
public class LoginAspectExceptionHandler {

    @Autowired
    private ProjectUrlConfig projectUrlConfig;

    /*拦截登录异常*/
    @ExceptionHandler(value = LoginAspectException.class)
    public ModelAndView handlerAuthorizeException(){
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = requestAttributes.getRequest();
        request.setAttribute("returnUrl","/ftl/auth");
        request.setAttribute("message","请先登录!");
        return new ModelAndView("common/msg_error");
    }



}
